﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lenovo.CFI.Common.Sys
{
    public class User
    {
        #region ctor

        /// <summary>
        /// 构造函数
        /// </summary>
        public User()
            : base()
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="itCode">itCode</param>
        public User(string itCode)
        {
        }

        public User(string itCode, string superior, string manager, string vp)
        {
            this.itCode = itCode;
            this.superior = superior;
            this.manager = manager;
            this.vp = vp;
        }

        public User(string itcode, Guid guid)
        {
            // TODO: Complete member initialization
            this.itcode = itcode;
            this.guid = guid;
        }

        #endregion

        #region field

        private string itCode;
        private string realName;
        private string phone;
        private string superior;
        private int permLevel;
        private bool enabled;
        private List<string> roles;
        private int teamID;
        private string manager;
        private string vp;
        private string itcode;
        private Guid guid;
        
        #endregion

        #region properity

        /// <summary>
        /// 获取或设置用户名
        /// </summary>
        public string ItCode
        {
            get
            {
                return this.itCode;
            }
            set
            {
                this.itCode = value.ToLower();
            }
        }

        /// <summary>
        /// 获取或设置姓名
        /// </summary>
        public string RealName
        {
            get { return realName; }
            set { realName = value; }
        }

        /// <summary>
        /// 获取或设置电话
        /// </summary>
        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }

        /// <summary>
        /// 获取ITS系统中的上级
        /// </summary>
        public string Superior
        {
            get { return superior; }
        }

        /// <summary>
        /// 获取或设置权限级别
        /// </summary>
        public int PermLevel
        {
            get { return permLevel; }
            set { permLevel = value; }
        }

        /// <summary>
        /// 获取或设置是否有效
        /// </summary>
        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }

        public List<string> Roles
        {
            get
            {
                if (this.roles == null)
                    this.roles = new List<string>();

                return this.roles;
            }
        }

        /// <summary>
        /// 获取用户Email
        /// </summary>
        public string Email
        {
            get { return String.Format("{0}@{1}", this.itCode, Utils.SysDomain()); }
        }

        /// <summary>
        /// 获取用户的显示名称和标识。
        /// </summary>
        public string DisplayID
        {
            get { return String.Format("{0}({1})", this.itCode, this.realName); }
        }


        /// <summary>
        /// 获取或设置所在Team
        /// </summary>
        public int TeamID
        {
            get { return teamID; }
            set { teamID = value; }
        }

        public string Manager
        {
            get { return manager; }
        }

        public string VP
        {
            get { return vp; }
        }


        public UserType Type
        {
            get 
            {
                if (itCode == vp)
                    return UserType.VP;
                else if (itCode == manager)
                    return UserType.Manager;
                else
                    return UserType.Employee;
            }
        }
        

        #endregion


        public enum UserType
        {
            Employee = 1,
            Manager = 2,
            VP = 3
        }
    }
}
